package dao;

import entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年09月10日11:28
 */
public interface UserMapper {

    // @Insert(value=" insert into t_user (username,password,phone,address) values (#{username},#{password},#{phone},#{address})")
    @Insert(" insert into t_user (username,password,phone,address) values (#{username},#{password},#{phone},#{address})")
    public void insertUser(User user);

    //强制一致
    // @Select(" select user_id 'id',user_username 'username',user_password 'password',user_phone 'phone',user_address 'address' from t_user2 where user_id=#{id}")
    @Select("select * from t_user2 where user_id=#{id}")

    // @Results相当于ResultMap标签的设置,通过value属性指定其值,该值是一个数组类型
    // 数组中每一个元素相当于ResultMap标签中的一个子标签
    // 每一个元素使用@Result表示,相当于id标签与result标签
    // @Result注解中，存在id属性，其值是一个布尔类型
    // 其值为true表示主键配置，其值为false表示普通字段，即：值为true相当于id标签，值为false相当于result标签
    @Results(value={
        @Result(id=true,property = "id",column = "user_id"),
        @Result(property = "username",column = "user_username"),
        @Result(property = "password",column = "user_password"),
        @Result(property = "phone",column = "user_phone"),
        @Result(property = "address",column = "user_address"),
    })
    public User selectUserById(Integer id);
}
